﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sms_send_log_View2Send.aspx.cs" Inherits="JKF.Web.SMS.Sms_send_log_View2Send" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <%= RegScript("~/js/jquery.1.5.js")%>
    <%= RegScript("~/js/jquery.nhis.js")%>
    <%= RegScript("~/js/jquery.rchis.js")%>
    <%= RegScript("~/js/jquery-ui-custom.min.js")%>
    <%=RegScript("~/js/jquery.json.js")%>
    <%= RegScript("~/js/css.js")%>
    <%= RegScript("~/js/DatePicker/WdatePicker.js")%>
    <%= RegScript("~/js/Common.js")%>
    <%= RegScript("~/js/Jquery.commonGrid.js")%>
    <%=this.RegStyle("~/App_Themes/Theme2/Include.css")%>
    <script type="text/javascript">
        var AppPath = '<%=AppPath %>';
        var handler = AppPath + '/do/SMS/SmsModule.do';
        var tmpl = new DTemplate();
        var PageSize = 20;
        var pager = null;
        var advSearch = null;
        var rowTemplate = "<tr pk=\"${TASK_KEY}\"><td><input type=\"button\" class=\"op_start mr12 btn_style\" style=\"display:${ShowStart}\" value=\"开启\"/><input type=\"button\" value=\"暂停\" class=\"op_stop mr12 btn_style\" style=\"display:${ShowStop}\"/><input type=\"button\" class=\"op-view mr12 btn_style\" value=\"查看执行日志\"/><input type=\"button\" class=\"op-del common_btn_del mr12\"/></td><td>${RECEIVER}</td><td>${CONTENT}</td><td>${PERIOD_TYPE_NAME}</td><td>${PERIOD_VALUE}</td><td>${STATUS_NAME}</td></tr>";
        $(function () {
            pager = $('#divPager').pager(AppPath, handler, { ActionName: 'GetSmsTasks' }, function (data) {
                var tbody = $('#tb tbody');
                tbody.empty();
                if (data && data.Entity && data.Entity.length) {
                    PreProcData(data.Entity);
                    tbody.html(tmpl(rowTemplate, data.Entity, true));
                } else {
                    tbody.html('<tr><td colspan="6" style="text-align: center">没有数据!</td></tr>');
                }
                $("#tb").H8_Grid($("#divPager"), (function () { var tbHeight = $(window).height() - 35; tbHeight -= ($(".common_search").size() > 0) ? $(".common_search").eq(0).height() : 0; tbHeight -= ($("#divPager").size() > 0) ? $("#divPager").height() : 0; return tbHeight < 300 ? 300 : tbHeight; })());
                BindGridEvent();
            }, PageSize, true);

            //$('#btnSearch').click(function () {
            //    pager.option.pageIndex = 1;
            //    pager.getPegerData();
            //    return false;
            //});
        });

        function PreProcData(data) {
            if (!data) return;
            $(data).each(function () {
                this.ShowStart = (this.STATUS == "0") ? "" : "none";
                this.ShowStop = (this.STATUS == "1") ? "" : "none";
            });
        }
        function BindGridEvent() {
            var tbody = $('#tb tbody');
            tbody.find(":button.op-view").click(function () {
                window.parent.pop("执行日志", '<%= ResolveUrl("~/sms/SmsTaskLog.aspx?taskKey=") %>' + $.FxNull($(this).parent().parent().attr("pk"), ""), 830, 500);
            });
            tbody.find(":button.op-del").click(function () {
                if (!confirm("确认要删除当前项吗？")) return;
                $.post(handler, { ActionName: "RemoveSmsTask", taskKey: $(this).parent().parent().attr("pk") }, function (rslt) {
                    if (rslt.Success) {
                        $(this).parent().parent().remove();
                        return;
                    }
                    alert(rslt.Message);
                });
            });
            tbody.find("a.op_start").click(function () {
                $.post(handler, { ActionName: "StartOrStopTask", taskKey: $(this).parent().parent().attr("pk"), status: "1" }, function (rslt) {
                    if (rslt.Success) {
                        PreProcData(rslt.Data);
                        var index = $('#tb tbody').find("tr[pk='" + rslt.Data.TASK_KEY + "']");
                        $(tmpl(rowTemplate, rslt.Data, true)).insertAfter(index);
                        index.remove();
                        BindGridEvent();
                        return;
                    }
                    alert(rslt.Message);
                }, "json");
            });
            tbody.find("a.op_stop").click(function () {
                $.post(handler, { ActionName: "StartOrStopTask", taskKey: $(this).parent().parent().attr("pk"), status: "0" }, function (rslt) {
                    if (rslt.Success) {
                        PreProcData(rslt.Data);
                        var index = $('#tb tbody').find("tr[pk='" + rslt.Data.TASK_KEY + "']");
                        $(tmpl(rowTemplate, rslt.Data, true)).insertAfter(index);
                        index.remove();
                        BindGridEvent();
                        return;
                    }
                    alert(rslt.Message);
                }, "json");
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="warrper_body">
            <div class="index">
                <%--<div class="common_search">
                    <div class="l_h45">
                        <input id="btnSearch" type="button" value="" class="common_btn_search" />
                    </div>
                </div>
                <div class="l_h7"></div>--%>
                <div class="index_table">
                    <table id="tb" class="common_table">
                        <thead>
                            <tr>
                                <th width="200px" orderaction="false">操作
                                </th>
                                <th width="100px" ordertype="string">接受者
                                </th>
                                <th width="250px" ordertype="string">短信内容
                                </th>
                                <th width="100px" ordertype="string">执行周期
                                </th>
                                <th width="200px" ordertype="string">执行时间
                                </th>
                                <th width="100px" ordertype="string">当前状态
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td colspan="6" style="text-align: center">点击搜索查看数据
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="page" id="divPager">
                </div>
            </div>
        </div>
    </form>
</body>
</html>
